import asyncio, pyautogui
import pygetwindow as gw
import os
import sys

async def timer_task(interval, callback):
    """一个可以停止的定时器"""
    while True:
        print("定时任务执行")
        callback()
        await asyncio.sleep(interval)  # 等待指定的时间间隔

def get_image_pos(image,  **kwargs):
  # print("get image pos %s", image)
  pos = None
  try:
    image_dir = os.getenv("IMAGE_DIR", get_executable_path())
    pos = pyautogui.locateCenterOnScreen(os.path.join(image_dir, image),  **kwargs)
  except Exception as e:
    pass
  return pos

def focus_wow():
  wow_window = None
  try:
    window = gw.getWindowsWithTitle('魔兽世界')
    # 如果找到窗口，则将其激活
    if window:
      wow_window = window[0]
      window[0].show()
      window[0].activate()
  except Exception as e:
    pass
  return wow_window

  
def get_executable_path():
  # sys.argv[0] 是可执行文件路径
  return os.path.dirname(os.path.abspath(sys.argv[0]))